home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 2001 May / SGI IRIX 6.5 Applications 2001 May.iso / dev / insight_dev.idb / usr / share / Insight / bin / make_bldsgml.z / make_bldsgml
Encoding:
Text File  |  2001-04-05  |  17.4 KB  |  598 lines

  1. #!/usr/bin/perl5
  2. # Creates buildable SGML source from parent SGML file and components.
  3. # Called by commondocrules for "make book.full" operation.
  4. #
  5. #       Daniel R. Dodge         Wed Oct 28 17:08:30 CST 1998
  6. #       originally written as "build-dweb-post" by Howard E. Pierce
  7. #
  8. # Requires perl5 to run correctly.
  9.  
  10. ################################################################################
  11. ### Define routine to handle various system signals and the signals that
  12. ### activate it:
  13.  
  14. sub SigHandler
  15. {
  16.    my ($Sig) = @_ ;
  17.  
  18.    if ("$SavEbtrc" ne '')
  19.    {
  20.       $ENV{'EBTRC'} = $SavEbtrc ;
  21.    }
  22.    chdir "$Pwd" ;
  23.    if ($OMask)
  24.    {
  25.       umask ($OMask) ;
  26.    }
  27. ## DRD  system ("/usr/bin/rm -rf $MkbookTmpDir $BookListLock") ;
  28.    print STDERR "\n\a$Name quits because of '$Sig' signal.\n" ;
  29.    exit 9 ;
  30. }
  31.  
  32. $SIG{'ABRT'} = 'SigHandler' ;        $SIG{'FPE'} = 'SigHandler' ;
  33. $SIG{'FREEZE'} = 'SigHandler' ;        $SIG{'HUP'} = 'SigHandler' ;
  34. $SIG{'ILL'} = 'SigHandler' ;        $SIG{'INT'} = 'SigHandler' ;   ### Ctrl-C
  35. $SIG{'KILL'} = 'SigHandler' ;        $SIG{'QUIT'} = 'SigHandler' ;
  36. $SIG{'SEGV'} = 'SigHandler' ;        $SIG{'STOP'} = 'SigHandler' ;
  37. $SIG{'TERM'} = 'SigHandler' ;        $SIG{'ALRM'} = 'SigHandler' ;
  38. $SIG{'BUS'} = 'SigHandler' ;        $SIG{'CONT'} = 'SigHandler' ;
  39. $SIG{'EMT'} = 'SigHandler' ;        $SIG{'LWP'} = 'SigHandler' ;
  40. $SIG{'PIPE'} = 'SigHandler' ;        $SIG{'POLL'} = 'SigHandler' ;
  41. $SIG{'PROF'} = 'SigHandler' ;        $SIG{'PWR'} = 'SigHandler' ;
  42. $SIG{'RTMAX'} = 'SigHandler' ;        $SIG{'RTMAX-1'} = 'SigHandler' ;
  43. $SIG{'RTMAX-2'} = 'SigHandler' ;    $SIG{'RTMAX-3'} = 'SigHandler' ;
  44. $SIG{'RTMIN'} = 'SigHandler' ;        $SIG{'RTMIN+1'} = 'SigHandler' ;
  45. $SIG{'RTMIN+2'} = 'SigHandler' ;    $SIG{'RTMIN+3'} = 'SigHandler' ;
  46. $SIG{'SYS'} = 'SigHandler' ;        $SIG{'THAW'} = 'SigHandler' ;
  47. $SIG{'TRAP'} = 'SigHandler' ;        $SIG{'TSTP'} = 'SigHandler' ;
  48. $SIG{'TTIN'} = 'SigHandler' ;        $SIG{'TTOU'} = 'SigHandler' ;
  49. $SIG{'URG'} = 'SigHandler' ;        $SIG{'USR1'} = 'SigHandler' ;
  50. $SIG{'USR2'} = 'SigHandler' ;        $SIG{'VTALRM'} = 'SigHandler' ;
  51. $SIG{'WAITING'} = 'SigHandler' ;    $SIG{'XCPU'} = 'SigHandler' ;
  52. $SIG{'XFSZ'} = 'SigHandler' ;
  53.  
  54.  
  55. ################################################################################
  56. ### Waits for user input to exit
  57. ###    $1 = Numeric exit code
  58. ###    $2 = InterActive flag
  59.  
  60. sub WaitAndExit
  61. {
  62.    if ("$SavEbtrc" ne '')
  63.    {
  64.       $ENV{'EBTRC'} = $SavEbtrc ;
  65.    }
  66.  
  67.    chdir "$Pwd" ;
  68.    if ($OMask)
  69.    {
  70.        umask ($OMask) ;
  71.    }
  72.  
  73.    if ($_[1])
  74.    {
  75.       print "\nPress RETURN to continue:  " ;
  76.       $NoOp = <STDIN> ;
  77.    }
  78.  
  79.    exit $_[0] ;
  80. }
  81.  
  82.  
  83. ################################################################################
  84. ### Subroutine to run system command lines, check for errors, & issue messages
  85. ###    $1 - $n = The system command lines to run
  86.  
  87. sub RunIt
  88. {
  89.    my ($CmdLine, $ECode) ;
  90.  
  91.    foreach $CmdLine (@_)
  92.    {
  93.       $ECode = system ("$CmdLine") ;
  94.       if ($ECode)
  95.       {
  96.          if ($ECode > 255)  { $ECode /= 256 ; }
  97.          print STDERR "\a\n$Name:  $ECode from:\n\t$CmdLine\n" ;
  98.          &WaitAndExit ("$ECode", "$InterActive")
  99.       }
  100.    }
  101. }
  102.  
  103.  
  104.  
  105. ################################################################################
  106. ### Replaces hard returns in nonwrapping elements with the <newline> element
  107. ### This is used only for InSight/DynaWeb processing of buildable source
  108. ###    $1 = String containing the name of the SGML file
  109. ###    $2 = String containing one complete SGML file
  110.  
  111. sub DoNewLines {
  112.    my ($FileName, $Buff) = @_ ;
  113.    my ($Start, $Tag, $Stop, $ToChange, $String) ;
  114.  
  115.    LOOP4:
  116.    while ($$Buff =~ m<(literallayout|programlisting|screen|synopsis[^>]+format="yes")[\s>]gis) {
  117.       $Start = pos ($$Buff) ;
  118.       $Tag = $1 ;
  119.       $Tag =~ s\s.*$s ;
  120.       $Stop = index ($$Buff, "</$Tag>", $Start) ;
  121.       if ($Stop < 0) {
  122.          print STDERR "\n\a<$Tag> missing end tag in '$FileName'!\n" ;
  123.          next LOOP4 ;
  124.       }
  125.       ### -- and ++ so that <newline> NOT added right after/b4 start/end tags 
  126.       $ToChange = --$Stop - ++$Start ;
  127.       if ($ToChange > 0) {  ### Ignore any empty tag pairs
  128.          $String = substr ($$Buff, $Start, $ToChange) ;
  129.          if ($String =~ s *\n<newline>gs) {  ### Remove spaces at EOLN
  130.             substr ($$Buff, $Start, $ToChange) = $String ;
  131.             $Stop += length ($String) - $ToChange ;
  132.       }  }
  133.       $Stop += length ("</$Tag>") ;
  134.       pos ($$Buff) = $Stop ;
  135. }  }
  136.  
  137.  
  138.  
  139. ################################################################################
  140. ### Cleans up SGML files:  Removes Adept processing instructions and joins
  141. ### tags broken across lines
  142. ### This contains both general SGML cleanup and InSight/Dynaweb tweaks
  143. ###    $1 = Name of file
  144. ###    $2 = String containing one complete SGML file
  145.  
  146. sub CleanUp {
  147.    my ($FileName, $Buff) = @_ ;
  148.    my (@Tmp, $Ent, %Tmp, @Ents, $Tmp) ;
  149.  
  150.  
  151.    ### General cleanup ######################################################
  152.  
  153.    ### change the \r\n output from spam into single carriage-returns
  154.    $$Buff =~ s\r\r\n\ng ;  ## sometimes two \r passthru by spam
  155.    $$Buff =~ s\r\n\ng ;
  156.    $$Buff =~ s\rg ;
  157.  
  158.    ### Join line-broken tags:
  159.    ##  SGML allows this: <section
  160.    ##                    id="thing1"
  161.    ##                    >
  162.    ##  But processing in scripts simplified if < to > on one line.
  163.    while ($$Buff =~ s(<[^>]+)[\n]$1 g)
  164.       { $NoOp = 1 ; }
  165.  
  166.    ### Delete all SGML-standard comments:
  167.    $$Buff =~ s<!--.*?-->gs ;
  168.    $$Buff =~ s<!>gs ;
  169.  
  170.    ### Replace DynaWeb packaging "collections" contents with empty tags:
  171.    ### This can be removed once the <collections> tag is no longer supported
  172.    $$Buff =~ s<collections.*?</collections><collections></collections>gis ;
  173.  
  174.    ### End of general cleanup ###############################################
  175.  
  176.  
  177.    ### InSight-specific changes #############################################
  178.  
  179.    ### Change all carriage-return processing instructions to newline elements:
  180.    $$Buff =~ s<\?Pub\s*_(newline>)<$1g ;
  181.  
  182.    ### Remove Adept processing instructions:
  183.    $$Buff =~ s\n<\?[^>]+>\n\ng ;
  184.    $$Buff =~ s<\?[^>]+>g ;
  185.  
  186.    ### Fix <stuff> problem for mkbook parser:
  187.    ##  first change all <sgmltag> to SGML_TAGOsgmltagSGML_TAGC :
  188.    $$Buff =~ s<([^>]*)>SGML_TAGO$1SGML_TAGCgs ;
  189.    ##  change leftover > chars to > :
  190.    $$Buff =~ s>>gs ;
  191.    ##  change delimiters back:
  192.    $$Buff =~ sSGML_TAGO<gs ;
  193.    $$Buff =~ sSGML_TAGC>gs ;
  194.  
  195.    ### Change certain character entities to literals (stylesheet bugs):
  196.    $$Buff =~ s–-gs ;
  197.    $$Buff =~ s—--gs ;
  198.    $$Buff =~ s  gs ;
  199.    $$Buff =~ s…...gs ;
  200.  
  201.    ### Change entityref values to include .gif extension:
  202.    ##  Might have <graphic entityref="abc" magnification="90"></graphic>
  203.    ##  or have <graphic magnification="90" entityref="abc"></graphic>
  204.    $$Buff =~ s<graphic([^>]*)entityref\s*=\s*\"([^"]*)\"<graphic$1entityref=\"$2.gif\"igs ;
  205.  
  206.    ### Replace hard returns in nonwrapping elements with the <newline> element:
  207.    &DoNewLines ($FileName, $Buff) ;
  208.  
  209.    ### End of InSight-specific changes ######################################
  210. }
  211.  
  212.  
  213.  
  214. ################################################################################
  215. ### Returns content of a tag pair
  216. ###    $1 = Array index at which to start looking
  217. ###    $2 = tag name (SGML requires case-insensitive match)
  218. ###    $3 = Array in which to search
  219.  
  220. sub GetTagContent {
  221.    my ($I, $Tag, $Buff) = @_ ;
  222.    my ($J, $Content, ) ;
  223.  
  224.    while ( ($$I <= $#$Buff) && ($$Buff[$$I] !~ m<$$Tag\bi) )
  225.    {
  226.       $$I++ ;
  227.    }
  228.    $J = $$I ;
  229.    while ( ($J <= $#$Buff) && ($$Buff[$J] !~ m</$$Tag\bi) )
  230.    {
  231.       $J++ ;
  232.    }
  233.    if ($$I == $J)
  234.    {
  235.       $Content = $$Buff[$$I] ;
  236.    }
  237.    else
  238.    {
  239.       $Content = join (' ', @$Buff[$$I..$J]) ;
  240.    }
  241.    $Content =~ s/\n/ /g ;
  242.    $Content =~ s^.*<$$Tag[^>]*>(.*)</$$Tag.*$1i ;
  243.    $Content =~ s/  +/ /g ;
  244.    $Content =~ s/^ +// ;
  245.    $Content =~ s/ +$// ;
  246.  
  247.    return ($Content) ;
  248. }
  249.  
  250.  
  251. ################################################################################
  252. ### Returns value for an attribute of an element
  253. ###    $1 = Array index at which to start looking
  254. ###    $2 = tag name (SGML requires case-insensitive match)
  255. ###     $3 = attribute name (SGML requires case-insensitive match)
  256. ###    $4 = Array in which to search
  257.  
  258. sub GetAttValue {
  259.    my ($I, $Tag, $AttribName, $Buff) = @_ ;
  260.    my ($J, $TagContent, $AttValue) ;
  261.  
  262.    ### Find the element (tag might be lowercase or uppercase)
  263.    while ( ($$I <= $#$Buff) && ($$Buff[$$I] !~ m<$$Tag\bi) )
  264.    {
  265.       $$I++ ;
  266.    }
  267.    $J = $$I ;
  268.    while ( ($J <= $#$Buff) && ($$Buff[$J] !~ m</$$Tag\bi) )
  269.    {
  270.       $J++ ;
  271.    }
  272.    if ($$I == $J)
  273.    {
  274.       $TagContent = $$Buff[$$I] ;
  275.    }
  276.    else
  277.    {
  278.       $TagContent = join (' ', @$Buff[$$I..$J]) ;
  279.    }
  280.  
  281.    $TagContent =~ s/\n/ /g ;
  282.    $TagContent =~ s^.*<$$Tag([^>]*)>.*$1i ;
  283.    ($AttValue = $TagContent) =~ s^.*\s$$AttribName\s*=\s*\"([^"]*)\".*$1i ;
  284.  
  285.    return ($AttValue) ;
  286.  
  287. }
  288.  
  289.  
  290. ################################################################################
  291. ### Gets information from book SGML file
  292. ###    $1 = Book name; returned by this routine
  293. ###    $2 = Complete publication number; returned by this routine
  294. ###    $3 = Book's version; returned by this routine
  295. ###    $4 = Book's Title; returned by this routine
  296. ###     $5 = Book's shorttitle attribute; returned by this routine
  297. ###     $6 = Book's bookshelf attribute; returned by this routine
  298. ###    $7 = Array of lines from text of book file
  299.  
  300. sub GetBookInfo {
  301.    my ($BookName, $PartNo, $Version, $Title, $ShortTitle,
  302.        $BookShelf, $BuffSGML) = @_ ;
  303.    my ($ClassCode, $Base, $Answer, $I, $AttribName, $Tag,
  304.        $PartInfo, $Tmp, @Tmp, $ChapSuffix) ;
  305.  
  306.    undef $$BookName ;
  307.    undef $$PartNo ;
  308.    undef $ClassCode ;
  309.    undef $Base ;
  310.    undef $$Version ;
  311.  
  312.    undef $$ShortTitle ;
  313.    undef $$BookShelf ;
  314.  
  315.  
  316.    ## DRD Future version:
  317.    ## Need to check value in the SGML file against the one in the Makefile.  If not 
  318.    ## the same, ask user if the value in the Makefile should be used.
  319.    ## Default = yes (need to be able to use Makefile to override values in the SGML file.
  320.  
  321.    if (grep (/<partnumber\b/i, @$BuffSGML))
  322.    {
  323.       $I = 0 ;
  324.       $Tag = 'partnumber' ;
  325.       $PartInfo = &GetTagContent (\$I, \$Tag, $BuffSGML) ;
  326.  
  327.       $I = 0 ;
  328.       $Tag = 'partnumber' ;
  329.       $AttribName = 'shorttitle' ;
  330.       $$ShortTitle = &GetAttValue (\$I, \$Tag, \$AttribName, $BuffSGML) ;
  331.  
  332.       ($ClassCode = $PartInfo) =~ s^.*<classcode[^>]*>(.*)</classcode>.*$\1i ;
  333.       ($Base = $PartInfo) =~ s^.*<base[^>]*>(.*)</base>.*$\1i ;
  334.       ($$Version = $PartInfo) =~ s^.*<version[^>]*>(.*)</version>.*$\1i ;
  335.       $$PartNo = "${ClassCode}-${Base}-$$Version" ;
  336.    }
  337.    else
  338.    {
  339.       print "\n$Name: Only for processing entire book! \n" ;
  340.       &WaitAndExit ("1", "$InterActive") ;
  341.    }
  342.  
  343.    ## Get "title" (full title)
  344.    $I = 0 ;
  345.    $Tag = 'title' ;
  346.    $$Title = &GetTagContent (\$I, \$Tag, $BuffSGML) ;
  347.    $$Title =~ s/\&[^;]+;//g ;  ### Remove any character entities
  348.  
  349.    $$BookName = $$PartNo ;
  350. }
  351.  
  352.  
  353.  
  354.  
  355. ################################################################################
  356. #####                                MAIN                                  #####
  357. ################################################################################
  358.  
  359.  
  360. $[ = 0 ;
  361. ($Name = $0) =~ s^.*/ ;
  362. select((select(STDOUT), $| = 1)[0]) ;   ### No buffering of stdout for messages
  363. $Usage = "
  364. Usage:  $Name  [-draft] [-numheads] -I<inputfile> -O<outputfile>
  365.  
  366.     -draft  
  367.                 Draft version; keep the comments and revision indicators
  368.                 for reviewers in displayed version (InSight or the
  369.                 'post4review' DynaWeb copies).
  370.  
  371.     -numheads
  372.         Inserts the numheads=Y attribute on the <sgidocbk>
  373.         tag for use by the stylesheets
  374.  
  375.     <inputfile>
  376.         Name of the .tmp SGML file generated by 'spam' in the
  377.                 current book's working directory.
  378.  
  379.         <outputfile>
  380.                 Name of the final buildable source file, by convention
  381.                 the <shorttitle>.sgml name.  
  382.  
  383.         Example:
  384.  
  385.            $Name -draft -IFSafe_IG.sgml.tmp -OFSafe_IG.sgml
  386. " ;
  387.  
  388.  
  389. chop ($Pwd = `/usr/bin/pwd`) ;
  390. $SgmlDocPath = "$Pwd" ;         ## DRD revised this variable 
  391.  
  392. ## definitions
  393. $ToolRoot = $ENV{'TOOLROOT'} ;
  394. $DraftVersion = 0 ;   ## flag for draft or final (default is final; strip <comment> elements)
  395.  
  396. $Indexer = "$ToolRoot/usr/share/Insight/bin/indexgen_sgidocbk" ;
  397. $XformSGML_public = "$ToolRoot/usr/share/Insight/bin/xformsgml_public" ;
  398.  
  399. $TmpFile = "tmp_make_bldsgml.$$" ;    ## temporary file(s) created and deleted
  400.                                       ## by this script
  401.  
  402. $InterActive = 0 ;        ## set to 1 if using from Adept-spawned shell window
  403. $NumberedHeads = 0;
  404.  
  405. if (! @ARGV) {
  406.    print STDERR "$Usage" ;
  407.    &WaitAndExit ("1", "$InterActive") ;
  408. }
  409.  
  410. while (@ARGV) {
  411.    $Arg = shift (@ARGV) ;
  412.    if ("$Arg" eq '-draft')
  413.    {
  414.       $DraftVersion = 1 ;
  415.    }
  416.    elsif ($Arg eq '-numheads')
  417.    {
  418.       $NumberedHeads = 1;
  419.    }
  420.    elsif ($Arg =~ /^-I.+/)
  421.    {
  422.       $Arg =~ s/^-I// ;
  423.       push (@Files, "$Arg") ;
  424.       $InputFile = $Arg ;
  425.    }
  426.    elsif ($Arg =~ /^-O.+/)
  427.    {
  428.       $Arg =~ s/^-O// ;
  429.       push (@Files, "$Arg") ;
  430.       $OutputFile = $Arg ;
  431.    }
  432.    elsif ($Arg =~ /^-/) {
  433.       print STDERR "\n\aUnrecognized option, '$Arg'$Usage" ;
  434.       &WaitAndExit ("1", "$InterActive") ;
  435.    }
  436. }
  437.  
  438.  
  439. if ("$InputFile" eq '')
  440.    {
  441.    print STDERR "$Usage" ;
  442.    &WaitAndExit ("1", "$InterActive") ;
  443.    }
  444.  
  445. if ("$OutputFile" eq '')
  446.    {
  447.    print STDERR "$Usage" ;
  448.    &WaitAndExit ("1", "$InterActive") ;
  449.    }
  450.  
  451. if (! @Files)
  452.    {
  453.    print STDERR "$Usage" ;
  454.    &WaitAndExit ("1", "$InterActive") ;
  455.    }
  456.  
  457.  
  458.  
  459. if (! $DraftVersion)
  460.    { print "\nPreparing buildable source SGML for FINAL version...\n" ; }
  461. else
  462.    { print "\nPreparing buildable source SGML for DRAFT version...\n" ; }
  463.  
  464.  
  465. ## DRD Need to add a check previous to this in the process to
  466. ##     check for use of file entities within <comment> elements.
  467. ##     Writers aren't supposed to use file entities in <comment>
  468. ##     elements because it is too easy to have a big chunk of text
  469. ##     "disappear" from final output.  This check needs to be done
  470. ##     on the component SGML files before the buildable SGML source
  471. ##     is made (spam resolves the references).
  472.  
  473.  
  474. ## DRD work out how to do this without so many temporary files later....
  475.  
  476.    ### Clean up the SGML instance:
  477.    print "\n    Preparing SGML instance for processing..." ;
  478.    if (! open (FileI, "$InputFile")) {
  479.       print STDERR "\a\n$Name:  $InputFile\"\n" ;
  480.       &WaitAndExit ("16", "$InterActive") ;
  481.    }
  482.    undef $/ ;
  483.    $Buff = <FileI> ;
  484.    close (FileI) ;
  485.    $/ = "\n" ;
  486.    $FileName = "$InputFile" ;
  487.    &CleanUp (\$FileName, \$Buff) ;
  488.  
  489.    if (! (open (FileZ, "> $TmpFile"))) {
  490.       print STDERR "\a\n$Name:  $TmpFile\n" ;
  491.       &WaitAndExit ("13", "$InterActive") ;
  492.    }
  493.    print FileZ join ('', $Buff) ;
  494.    close (FileZ) ;
  495.    print "..done.\n" ;
  496.  
  497.  
  498.    ### Make public version of file if not making draft version.
  499.    ##  Replace TmpFile with public version. 
  500.    if (! $DraftVersion)
  501.    {
  502.       $ErrorCode = system ("$XformSGML_public -I$TmpFile -O$TmpFile.2") ;
  503.       if (! $ErrorCode)
  504.       {
  505.          system ("rm -f $TmpFile") ;
  506.          system ("mv $TmpFile.2 $TmpFile") ;
  507.       }
  508.    }
  509.  
  510.  
  511.    ### Build the writer's (back-of-book) index:
  512.    ##  (This is specific for Insight.)
  513.    print "\n    Processing writer's index...\n" ;
  514.    &RunIt ("$Indexer -i $TmpFile -o $TmpFile.idx") ;
  515.    print "    writer's index generated.\n" ;
  516.  
  517.    ### Put generated index into SGML instance:
  518.    print "\n    Integrating writer's index..." ;
  519.  
  520.  
  521.    ##  Get the book info from the SGML instance:
  522.    if (! open (FileA, "$TmpFile")) {
  523.       print STDERR "\a\n$Name:  $TmpFile\"\n" ;
  524.       &WaitAndExit ("16", "$InterActive") ;
  525.    }
  526.    undef $/ ;
  527.    @BuffSGML = <FileA> ;
  528.    close (FileA) ;
  529.    $/ = "\n" ;
  530.    &GetBookInfo (\$BookName, \$PartNo, \$Version, \$Title,
  531.                  \$ShortTitle, \$BookShelf, \@BuffSGML) ;
  532.  
  533.    ### Compare shorttitle from SGML with value from Makefile:
  534.    ($InputShortTitle = $OutputFile) =~ s(.*).sgml\1 ;
  535.  
  536.    if ("$InputShortTitle" ne "$ShortTitle")
  537.    {
  538.       print "\n\nCAUTION! The short title in the Makefile is different" ;
  539.       print "\nthan the value in the SGML file." ;
  540.       print "\n  Short title from Makefile = $InputShortTitle " ;
  541.       print "\n  Short title from SGML = $ShortTitle " ;
  542.       print "\nContinuing, but using value from Makefile.\n\n" ;
  543.    }
  544.  
  545.  
  546.  
  547.    ### Open the "indexless" SGML instance:
  548.    if (! open (FileS, "$TmpFile")) {
  549.       print STDERR "\a\n$Name:  $TmpFile.2\"\n" ;
  550.       &WaitAndExit ("16", "$InterActive") ;
  551.    }
  552.    undef $/ ;
  553.    $Buff1 = <FileS> ;
  554.    close (FileS) ;
  555.    $/ = "\n" ;
  556.  
  557.    ##  Open the index file:
  558.    if (! open (FileB, "$TmpFile.idx")) {
  559.       print STDERR "\a\n$Name:  $TmpFile.idx\"\n" ;
  560.       &WaitAndExit ("16", "$InterActive") ;
  561.    }
  562.    undef $/ ;
  563.    $Buff2 = <FileB> ;
  564.    close (FileB) ;
  565.    $/ = "\n" ;
  566.  
  567.    ##  Open the final shorttitle.sgml output file:
  568.    if (! (open (FileZ, "> $OutputFile"))) {
  569.       print STDERR "\a\n$Name:  $Outputfile\n" ;
  570.       &WaitAndExit ("13", "$InterActive") ;
  571.    }
  572.  
  573.    ###  Insert the index into the SGML file:
  574.    $Buff1 =~ s<index></index>$Buff2gi ;
  575.  
  576.    ### Change shorttitle attribute value to Makefile value:
  577.    ##  Might have <partnumber shorttitle="xyz" bookshelf="sgi-admin">
  578.    ##  or <partnumber bookshelf="sgi-admin" shorttitle="xyz">
  579.    $Buff1 =~ s<partnumber([^>]*)shorttitle\s*=\s*\"([^"]*)\"<partnumber$1shorttitle=\"$InputShortTitle\"ig ;
  580.  
  581.    # add the NUMHEADS attribute to <sgidocbk> if needed
  582.    if($NumberedHeads == 1) {
  583.     $Buff1 =~ s/(<sgidocbk)/\1 NUMHEADS="Y"/i;
  584.    }
  585.  
  586.    print FileZ join ('', $Buff1) ;
  587.    close (FileZ) ;
  588.    print "..done.\n" ;
  589.  
  590.    ### Remove temporary files:
  591.    unlink "$TmpFile" ;
  592.    unlink "$TmpFile.idx" ;
  593.  
  594.    print "\n...buildable source SGML done.\n\n" ;
  595.  
  596.  
  597. &WaitAndExit ("0", "$InterActive") ;
  598.